#include "Tower.h"
#include "Entity.h"
#include "../SGD Wrappers/CSGD_TextureManager.h"
#include "../SGD Wrappers/CSGD_Direct3D.h"
#include "../SGD Wrappers/CSGD_DirectInput.h"
#include "Game.h"
#include "GameplayState.h"
#include "AnimationInfo.h"
#include "AnimationManager.h"

CTower::CTower(void)
{
	TypeofObj = Obj_Tower;
	m_pAnimManager = CAnimationManager::GetInstance();
	//m_pCurrAnimInfo = new CAnimationInfo();
	m_pCurrAnimInfo.SetCurrentAnimation( "PC_PlayerWalkLeft" );
	//m_pCurrAnimInfo->AddRef();
	pDI = CSGD_DirectInput::GetInstance();
}


CTower::~CTower(void)
{
	//delete m_pCurrAnimInfo;
	//m_pCurrAnimInfo = nullptr;

	//m_pCurrAnimInfo->Release();
}

void CTower::Update( float fElapsedTime )
{
	
	CEntity::Update(fElapsedTime);
	m_pAnimManager->Update( &m_pCurrAnimInfo, fElapsedTime );

	if(pDI->KeyPressed( DIK_Z ) )
	{
		m_pCurrAnimInfo.SetCurrentAnimation( "PC_PlayerWalkLeft" );
		// Make sure to reset frames to 0 so vector subscript does not go out of range!!!!!!!!!!!!!!!!!!!!!!!!!!!!
		m_pCurrAnimInfo.SetCurrentFrame( 0 );

	}
	if(pDI->KeyPressed( DIK_X ) )
	{
		m_pCurrAnimInfo.SetCurrentAnimation( "zombie" );
		// Make sure to reset frames to 0 so vector subscript does not go out of range!!!!!!!!!!!!!!!!!!!!!!!!!!!!
		m_pCurrAnimInfo.SetCurrentFrame( 0 );
	}
}

void CTower::Render( void )
{
	CSGD_Direct3D::GetInstance()->GetSprite()->Flush();

	//Replace with the animation engine
	m_pAnimManager->Render( &m_pCurrAnimInfo, this->GetPosX(), this->GetPosY(), false, D3DCOLOR_RGBA(255, 255, 255, 255) );
	CSGD_TextureManager::GetInstance()->Draw(GetImageID(), (int)(GetPosX()), (int)(GetPosY()),
		2.0f,2.0f);
}

bool CTower::CheckCollision( IEntity* pOther )
{
	if( CEntity::CheckCollision(pOther) != true )
	{
		return false;
	}
	switch( pOther->GetType() )
		case Obj_Elemental:
	{
		SetVelY(-100);
		return true;
	}
	return false;
}